<template>
  <div>
  <div class='detail_page_header' v-if="showSign === 1">
    <el-page-header @back="goBack" content="信息详情"></el-page-header>
  </div>
  <dialogDetail ref="dialogDetail" v-if="showSign === 1"></dialogDetail>
  <div class="mod-config" v-show="showSign === 0">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        prop="dialId"
        header-align="center"
        align="center"
        label="对话关系id">
      </el-table-column>
      <el-table-column
        prop="userSendNickName"
        header-align="center"
        align="center"
        label="用户1">
      </el-table-column>
      <el-table-column
        prop="userRecvNickName"
        header-align="center"
        align="center"
        label="用户2">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="newTime"
        header-align="center"
        align="center"
        label="更新时间">
      </el-table-column>
      <el-table-column
        prop="newContent"
        header-align="center"
        align="center"
        label="最新消息">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showDialogDetail(scope.row.dialId)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
  </div>
  </div>
</template>

<script>
  import Detail from './detail'
  export default {
    data () {
      return {
        showSign: 0,
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      DialogDetail: Detail,
    },
    activated () {
      // this.getDataList()
      this.dataList = [
        {
          dialId:1,
          userSend:1,
          userRecv:2,
          createTime:'2021/04/28 12:00:00',
          newTime:'2021/05/28 12:00:00',
          newContent:'在么？2号',
        },{
          dialId:2,
          userSend:1,
          userRecv:3,
          createTime:'2021/04/28 12:00:00',
          newTime:'2021/05/28 12:00:00',
          newContent:'在么？3号',
        }
      ]
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        var data = {
          key:this.dataForm.key,
          page:''+this.pageIndex,
          limit:''+this.pageSize,
          sidx: 'create_time',
          order:'asc'
        }
        this.$http({
          url: this.$http.adornUrl('/user/dialog/relation/list'),
          method: 'post',
          data: this.$http.adornData(data, false),
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 显示 对话详情
      showDialogDetail(dialId){
        this.showSign = 1;
        this.$nextTick(() => {
          // console.log(this.$refs.dialogDetail);
          this.$refs.dialogDetail.init(dialId)
        });
      },
      // 返回 对话关系
      goBack(){
        this.showSign = 0;
      },
      
      
    }
  }
</script>
<style>
.detail_page_header{
  margin-bottom: 10px;
}

</style>